<?php

use app\models\AsrKeyword;
use app\models\AsrSeriousness;
use function foo\func;
use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\ArcrKeywordSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '质检机器人分类种类';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="arc-keyword-index">
    <h4>点击按钮添加关键字</h4>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('新增', ['create'], ['class' => 'btn btn-info fa fa-plus']) ?>
        <?= Html::a('选择关键字', ['views'], ['class' => 'btn btn-success fa fa-sticky-note-o']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showFooter' => true,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
                'attribute'=>'name',
                'value'=>function($model){
                    return $model->name;
                },
                'footer' => '<input id="num"  type="number" href="#" class="btn btn-default btn-xs btn-delete" placeholder="每页显示的条数"/>',
            ],
            [
                'attribute'=>'names',
                'value'=>function($model){
                 $id =  $model->seriousness_id;
                 $name = AsrSeriousness::find()->where(['id'=>$model->seriousness_id])->all();
                 //var_dump($model);
                 return  $name['0']['names'];
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{update}&nbsp;&nbsp;{delete}',
                'buttons' => [
                    'update'=> function ($url, $model, $key) {
                        return '<a href="'.$url.'" class="btn btn-info fa fa-edit">修改</a>';
                    },
                    'delete'=> function ($url, $model, $key) {
                        return '<a href="'.$url.'" title="删除" aria-label="删除" data-pjax="0" data-confirm="您确定要删除此项吗？删除此项会删除相应的电话号码记录。" data-method="post"><span class="btn btn-danger fa fa-remove">删除</span></a>';
                    },
                ],

            ],

        ],
    ]); ?>
</div>
<script type="text/javascript">
    $(function(){
        $("#num").blur(function(){//当鼠标失去焦点时就出发事件，实现分页的页改变
            var url = "<?= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ?>";
            $.ajax({
                type:"post",
                async:true,
                cache:false,
                url:url,/*url写异步的请求地址*/
                data:{
                    pageSize:$("#num").val()
                },
                success: function(datas){
                    window.location.reload()
                },
                error: function(error){
                }
            });
        });

    });
</script>
